package com.ld.admin.util.daliySentence.impl;

import org.apache.commons.lang.math.RandomUtils;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.ld.admin.util.daliySentence.DaliySentence;
import com.ld.admin.util.daliySentence.DaliySentenceUtil;
import com.ld.admin.util.daliySentence.model.DaliySentenceModel;
import com.ld.shieldsb.common.core.util.JsoupUtil;

/**
 * 
 * 句子控
 * 
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2020年1月8日 下午2:12:23
 *
 */
public class DaliySentenceJuzikong implements DaliySentence {
    public static final String KEY = "juzikong";
    public static final String NAME = "句子控";
    public static final String URL = "https://www.juzikong.com/discovery/hot";
    public static final String LINK_URL = URL;
    public static final String DESCRIPTION = "收集与分享你喜欢的句子"; // 描述

    @Override
    public DaliySentenceModel getSentence() {
        DaliySentenceModel model = null;
        String htmlContent = null;
        Document document = JsoupUtil.getRemoteURLDocument(getURL(), null);
        if (document != null) {
            model = new DaliySentenceModel();
            Elements contentCs = document.select("div.body_2xJQU");
            int random = RandomUtils.nextInt(20) % contentCs.size();
            Element contentEle = contentCs.get(random); // 内容
            htmlContent = contentEle.text() + DaliySentenceUtil.getLinkedStr(getLinkURL(), getName());

            model.setHtmlContent(htmlContent);
            model.setContent(contentEle.text());
//            model.setOrigin("");
            model.setBaseInfo(getBaseInfo());
        }
        return model;
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getURL() {
        return URL;
    }

    @Override
    public String getLinkURL() {
        return LINK_URL;
    }

    @Override
    public String getDescription() {
        return DESCRIPTION;
    }

}
